<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<script>
    function test2(url)
    {
        var xmlhttp;
        if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }
        else
        {
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }

        xmlhttp.onreadystatechange=function()
        {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
                document.getElementById('A1').innerHTML=xmlhttp.status;
                document.getElementById('A2').innerHTML=xmlhttp.statusText;
                document.getElementById('A3').innerHTML=xmlhttp.responseText;
            }
        }
            xmlhttp.open("GET",url,true);
            xmlhttp.send();
    }

</script>


    
</body>
    <h2>通过ajax从简单的xml文件中获取数据</h2>
    <p><b>Status:</b><span id="A1"></span></p>
    <p><b>Status text:</b><span id="A2"></span></p>
    <p><b>Response:</b><span id="A3"></span></p>
    <button onclick="test2('./demo2.xml')">Get XML data</button>

</html>


